package com.zxl.springcloud.service;

import com.zxl.springcloud.entity.Student;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *  studentService的熔断与降级
 */
@Component
public class StudentServiceFallbackFactory implements FallbackFactory<StudentService>{
    @Override
    public StudentService create(Throwable throwable) {
        return new StudentService() {
            @Override
            public List<Student> findAll() {
                return null;
            }

            @Override
            public Student get(Long id) {
                return  Student.builder()
                        .age(0L)
                        .class_no(0)
                        .id(0L)
                        .name("用户查询失败")
                        .gender("查询失败")
                        .phone("查询失败")
                        .build();
            }

            @Override
            public boolean add(Student student) {
                return false;
            }
        };
    }
}
